< previous page page_724 next page >

Page 724
Commenting Your Code
Each procedure and function should begin with a brief comment describing the functional characteristics of the routine (what it does). This description should not describe the implementation details (how it does it), because these often change over time, resulting in unnecessary comment maintenance work or, worse yet, erroneous comments. The code itself and any necessary inline or local comments should describe the implementation.
Parameters passed to a routine should be described when their function is not obvious and when the routine expects the parameters to be in a specific range. Function return values and global variables that are changed by the routine (especially through reference parameters) must also be described at the beginning of each routine.
Each nontrivial variable declaration should include an inline comment describing the use of the variable being declared.
Variables, controls, and routines should be named clearly enough that inline commenting is only needed for complex or nonintuitive implementation details.
An overview description of the application, enumerating primary data objects, routines, algorithms, dialog boxes, database and file system dependencies, and so on should be included at the start of the BAS module that contains the projects Visual Basic generic constant declarations.
9f31265bb40b592b1929e18a47ab28e5.gif
NOTE
The Project window inherently describes the list of files in a project, so this overview section only needs to provide information on the most important files and modules or the files the Project window doesnt list, such as initialization (INI) or database files.
Formatting Your Code
Because many programmers still use VGA displays, screen real estate must be conserved as much as possible while still allowing code formatting to reflect logic structure and nesting. Standard tab-based, block-nesting indentations should be three spaces. More than four spaces is unnecessary and can cause statements to be hidden or accidentally truncated. Less than two spaces does not sufficiently show logic nesting. The highest-level statements that follow the overview comment should be indented one tab, with each nested block indented an additional tab. Heres an example:

 
< previous page page_724 next page >

If you like this book, buy it!